// TestCaseModel
// (c)2007 Mark Bulmahn. mBulmahn@web.de
// License: GPL 2.0
// Project: TestCaseGenerator. http://www.codeplex.com/TestCaseGenerator

using System;
using System.Collections.Generic;
using System.Text;
using SerializationHelperLib;

namespace TestCaseModel
{
    /// <summary>
    /// A list of test case parameters that are used in a model to describe
    /// the possible states a testobject can take.
    /// </summary>
    [Serializable]
    public class Parameters : XmlSerializableDictionary<string, Parameter>
    {
        public List<Parameter> SortedParameters
        {
            get
            {
                SortedDictionary<int, Parameter> sortedList = new SortedDictionary<int, Parameter>();
                foreach (Parameter p in this.Values)
                {
                    sortedList.Add(p.OrderId, p);
                }
                return new List<Parameter>(sortedList.Values);
            }
        }

        public int GetNewOrderId()
        {
            int max = 0;
            foreach (Parameter p in this.Values)
                if (p.OrderId > max)
                    max = p.OrderId;
            return max + 1;
        }

        public void MoveDown(Parameter par)
        {
            foreach (Parameter p in this.Values)
            {
                if (p.OrderId == par.OrderId + 1)
                {
                    p.OrderId--;
                    par.OrderId++;
                    break;
                }
            }
        }

        public void MoveUp(Parameter par)
        {
            foreach (Parameter p in this.Values)
            {
                if (p.OrderId == par.OrderId - 1)
                {
                    p.OrderId++;
                    par.OrderId--;
                    break;
                }
            }
        }
    }
}
